﻿using System;
using StreetPacMan.Server.Facade;
using StreetPacMan.Server.HardcodedGameData;
using StructureMap;

namespace StreetPacMan.Server.Infra
{
    internal static class Filler_ForDebuggingPurposes
    {
        public static void Fill()
        {
            Bootstrapper.Bootstrap();
            ObjectFactory.Inject<IConnectionProvider>(new ConnectionProvider());
            ObjectFactory.Inject<IJunctionsProvider>(new MasarikJunctionsProvider());
            var server = ObjectFactory.GetInstance<IServerFacade>();

            var gameName = "Masarik";
            server.CreateGame(new CreateGameParameters(gameName));

            var p = server.JoinGame(new JoinGameParameters(gameName, "Hamutal", PlayerRole.PacMan));
            server.JoinGame(new JoinGameParameters(gameName, "G3", PlayerRole.Ghost));

            Console.Write("First player id: " + (p.PlayerId-1));
        }

        public static void Cleanup()
        {
            using (var dbConnection = new ConnectionProvider().GetConnection())
            using (var pacManDataContext = new PacManDataContext(dbConnection))
            {
                pacManDataContext.ExecuteCommand(GetCleanupCommandString());
            }

            //using (var pacManDataContext = new PacManDataContext(dbConnection))
            //{
            //    pacManDataContext.Apples.DeleteAllOnSubmit(pacManDataContext.Apples);
            //    pacManDataContext.Players.DeleteAllOnSubmit(pacManDataContext.Players);
            //    pacManDataContext.Events.DeleteAllOnSubmit(pacManDataContext.Events);
            //    pacManDataContext.Games.DeleteAllOnSubmit(pacManDataContext.Games);
            //    pacManDataContext.SubmitChanges();
            //}
        }

        public static string GetCleanupCommandString()
        {
            return "DELETE FROM Messages; DELETE FROM Apples; DELETE FROM Events; DELETE FROM Players; DELETE FROM Games; ";
        }

        public static void Test()
        {
            Bootstrapper.Bootstrap();
            ObjectFactory.Inject<IConnectionProvider>(new ConnectionProvider());
            ObjectFactory.Inject<IJunctionsProvider>(new MasarikJunctionsProvider());
            var server = ObjectFactory.GetInstance<IServerFacade>();
            server.REMOVEME_CopyApplesFromOneGameToAnother(new REMOVEME_CopyApplesFromOneGameToAnotherParameters( 929,933));
        }
    }
}